<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="/shop/include :: header"></head>
<body>
<form class="layui-form" action="" lay-filter="shop_merchants_store-add-form" style="margin-top: 20px;">
	<div style="display: flex">
		<!--  -->
		<div class="layui-form-item" style="display: contents">
			<label class="layui-form-label">店铺logo：</label>
			<div class="layui-upload-list" id="test1">
				<img class="layui-upload-img" id="demo1" style="width: 300px;height: 300px">
				<input type="hidden" name="storeLogo" id="storeLogo">
			</div>
		</div>
		<div style="width: 63%">
			<!--  -->
			<div class="layui-form-item">
				<label class="layui-form-label">用户ID：</label>
				<div class="layui-input-block">
					<input class="layui-input" lay-verify="required" autocomplete="off" id="userId"
						   name="userId"
						   placeholder="请输入用户ID">
				</div>
			</div>
			<!--  -->
			<div class="layui-form-item">
				<label class="layui-form-label">用户群体：</label>
				<div class="layui-input-block">
					<select name="userType" id="userType" placeholder="用户群体">
						<option value="0">供应商</option>
						<option value="1">商户</option>
						<option value="2">平台</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">店铺名称：</label>
				<div class="layui-input-block">
					<input class="layui-input" lay-verify="required" autocomplete="off" id="storeName"
						   name="storeName"
						   placeholder="请输入店铺名称">
				</div>
			</div>
			<!--  -->
			<div class="layui-form-item">
				<label class="layui-form-label">负责人：</label>
				<div class="layui-input-block">
					<input class="layui-input" lay-verify="required" autocomplete="off" id="responsibleName"
						   name="responsibleName"
						   placeholder="请输入店铺负责人">
				</div>
			</div>
			<!--  -->
			<div class="layui-form-item">
				<label class="layui-form-label">店铺电话：</label>
				<div class="layui-input-block">
					<input class="layui-input" lay-verify="required" autocomplete="off" id="storePhone"
						   name="storePhone"
						   placeholder="请输入店铺电话">
				</div>
			</div>
			<!--  -->
			<div class="layui-form-item">
				<label class="layui-form-label">店铺介绍：</label>
				<div class="layui-input-block">
					<input class="layui-input" lay-verify="required" autocomplete="off" id="storeDetail"
						   name="storeDetail"
						   placeholder="请输入店铺介绍">
				</div>
			</div>
		</div>
	</div>
	<!--  -->
	<div class="layui-form-item">
		<label class="layui-form-label">线下门店：</label>
		<div class="layui-input-block">
			<select name="isOffline" id="isOffline" placeholder="线下门店" lay-filter="isOffline">
				<option value="0">是</option>
				<option value="1">否</option>
			</select>
		</div>
	</div>
	<!--  -->
	<div class="layui-form-item" id="dOfflineAddress">
		<label class="layui-form-label">线下地址：</label>
		<div class="layui-input-block">
			<input class="layui-input" lay-verify="required" autocomplete="off" id="offlineAddress"
				   name="offlineAddress"
				   placeholder="请输入店铺线下地址">
		</div>
	</div>
	<!--  -->
	<div class="layui-form-item">
		<label class="layui-form-label">处理状态：</label>
		<div class="layui-input-block">
			<select name="applyState" id="applyState" lay-filter="applyState">
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">启用状态：</label>
		<div class="layui-input-block">
			<select id="enableState" name="enableState" lay-filter="enableState">
			</select>
		</div>
	</div>
	<!--  -->
	<div class="layui-form-item">
		<label class="layui-form-label">平台回复：</label>
		<div class="layui-input-block">
			<textarea id="platformReply" name="platformReply"></textarea>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="shop_merchants_store-add">立即提交</button>
		</div>
	</div>
</form>
<div th:include="/shop/include::footer"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
	layui.use([ 'layer', 'jquery', 'form', 'laydate', 'layedit' , "upload", 'dict'], function() {
		var $ = layui.jquery;
		var laydate = layui.laydate;
		var layer = layui.layer;
		var form = layui.form;
		var layedit = layui.layedit;
		var upload = layui.upload;
		var dict = layui.dict;

		dict.setSelect("enableState","enableState");
		dict.setSelect("applyState","applyState");
		var uploadInst = upload.render({
			elem: '#test1'
			, url: '/platform/UploadFile' //改成您自己的上传接口
			//, headers: {"token": layui.data(layui.setter.tableName)['token']}
			, before: function (obj) {
				//预读本地文件示例，不支持ie8
				obj.preview(function (index, file, result) {
					$('#demo1').attr('src', result); //图片链接（base64）
				});
			}
			, done: function (res) {
				//如果上传失败
				if (res.status != "SUCCESS") {
					return layer.msg('上传失败');
				}
				//上传成功
				layer.msg('上传成功');
				$("#storeLogo").val(res.data)
			}
			, error: function () {
				//演示失败状态，并实现重传
				var demoText = $('#demoText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function () {
					uploadInst.upload();
				});
			}
		});

		var platformReply =  layedit.build('platformReply',{
			tool: [
				'strong' //加粗
				,'italic' //斜体
				,'underline' //下划线
				,'del' //删除线

				,'|' //分割线

				,'left' //左对齐
				,'center' //居中对齐
				,'right' //右对齐
				,'link' //超链接
				,'unlink' //清除链接
				,'face' //表情
			]
		}); //建立编辑器

		form.on('select(isOffline)', function (dataObj) {
			var value = $("#isOffline").val();
			if (value == 0) {
				$("#dOfflineAddress").css('display', 'block');
			}
			if (value == 1) {
				$("#dOfflineAddress").css('display', 'none');
			}
		});

		//监听提交
		form.on('submit(shop_merchants_store-add)', function(data) {
			data.field.platformReply = layedit.getContent(platformReply);
			$.ajax({
				url: '/platform/userstore/add',
				type: "post",
				data: JSON.stringify(data.field),
				contentType: 'application/json; charset=utf-8', // 很重要
				async: false,
				success: function (result) {
					if (result.status == "SUCCESS"){
						layer.msg(result.message, {
							offset: '15px'
							, icon: 1
							, time: 1000
						}, function () {
							window.parent.location.reload();
						});
					}else {
						layer.msg(result.message)
					}
				}
			});
			return false;
		});
	});
</script>
</body>
</html>